const { filterFormWithEmptyValue } = require("./filter");

module.exports = function setResponse(
  ctx,
  data,
  total,
  successMessage = "成功",
  successCode = 200,
  errorMessage = "失败",
  errorCode = 500
) {
  if (data) {
    ctx.body = filterFormWithEmptyValue({
      code: successCode,
      message: successMessage,
      data: data,
      total,
    });
  } else {
    ctx.body = {
      code: errorCode,
      message: errorMessage,
      data: null,
    };
  }
};
